package sw.EngAdroid;

//Player will contain the following items for the game
//1) Name
//2) Number of permanent chips they have
//3) Number of games chips they have
//4) current score
//5) current bet
//6) bet ratio
//7) current answer to question

//Enzo: created multiple class variables as a plan in the future
//so that it could be easily accessible from the GUI standpoint

public class Player {
	private String player_name;
	private int permanent_chips;
	private int game_chips;
	private int curr_score;
	private int curr_bet;
	private long bet_ratio;
	private String curr_answer;
	protected Game currentGame;
	private int chips_bet;

	// default constructor, no assignments
	public Player() {

	}

	public Player(String name) {
		player_name = name;
		permanent_chips = 2;
		game_chips = 0;
		chips_bet = 0;
	}

	// constructor that assigns in player_name, permanent_chips to it
	public Player(String player_name, int permanent_chips) {
		this.player_name = player_name;
		this.permanent_chips = permanent_chips;
		game_chips = 0;
		curr_score = 0;
		curr_bet = 0;
		bet_ratio = 0;
	}

	public int getChipsBet() {
		return chips_bet;
	}

	public void setChipsBet(int bet) {
		chips_bet = bet;
	}

	public void printChips() {
		System.out.println(player_name);
		System.out.println(permanent_chips);
		System.out.println(game_chips);
	}

	public void placeBet(int choice, int chips) {
		int totalChips = game_chips + permanent_chips;
		int permanentChips = 0;
		if (chips > totalChips) {
			chips = totalChips - permanent_chips;
			permanentChips = 2;
		}
		if (chips > totalChips - chips_bet) {
			chips = totalChips - chips_bet;
		}
		Bet bet = new Bet(player_name, choice, permanentChips, chips);
		currentGame.receiveBet(bet);
		chips_bet += chips;
	}
	
	public Bet getBet(int choice, int chips) {
		int totalChips = game_chips + permanent_chips;
		int permanentChips = 0;
		if (chips > totalChips) {
			chips = totalChips - permanent_chips;
			permanentChips = 2;
		}
		if (chips > totalChips - chips_bet) {
			chips = totalChips - chips_bet;
		}
		Bet bet = new Bet(player_name, choice, permanentChips, chips);
		return bet;
		
	}

	public Game getGame() {
		return currentGame;
	}

	public String joinGame(Game g) {
		if (g.addPlayer(this)) {
			currentGame = g;
			return this.player_name + " has been added to game " + g.getName();
		} else
			return this.player_name + " was not added to the game.  "
					+ g.getName()
					+ " is currently full.  Please try a different game.";
	}

	public void submitGuess(int num_guess) {
		Guess guess = new Guess(player_name, num_guess);
		currentGame.receiveGuess(guess);
	}

	// All getters and setters below this comment
	public String getPlayer_name() {
		return player_name;
	}

	public void setPlayer_name(String player_name) {
		this.player_name = player_name;
	}

	public int getPermanent_chips() {
		return permanent_chips;
	}

	public void setPermanent_chips(int permanent_chips) {
		this.permanent_chips = permanent_chips;
	}

	public int getGame_chips() {
		return game_chips;
	}

	public void setGame_chips(int game_chips) {
		this.game_chips = game_chips;
	}

	public int getCurr_score() {
		return curr_score;
	}

	public void setCurr_score(int curr_score) {
		this.curr_score = curr_score;
	}

	public int getCurr_bet() {
		return curr_bet;
	}

	public int getChips() {
		return game_chips + permanent_chips;
	}

	public void setCurr_bet(int curr_bet) {
		this.curr_bet = curr_bet;
	}

	public long getBet_ratio() {
		return bet_ratio;
	}

	public void setBet_ratio(long bet_ratio) {
		this.bet_ratio = bet_ratio;
	}

	public String getCurr_answer() {
		return curr_answer;
	}

	public void setCurr_answer(String curr_answer) {
		this.curr_answer = curr_answer;
	}
}